import '../../css/addNote.css';
import ajax from '../../utils/ajax';

const form = document.forms.add;
console.log(form);

form.onsubmit = form_submit;


function form_submit(e) {
  e.preventDefault()
  console.log(form.title);
  if (!form.title.value || !form.content.value) {
    alert('标题或内容不能为空')
    return;
  }
  ajax('post', '/api/addNote', {
    title: form.title.value,
    content: form.content.value,
  }).then(result => {
    alert(result.msg)
    if (confirm('你还需要发布吗？')) {
      form.reset();

    } else {
      location.assign('/index.html')
    }
  })
}